#include <iostream>
#include <unistd.h>
#include <signal.h>
#include <sys/types.h>
#include <cstdlib>

int count = 0;

void header(int signo)
{
    std::cout << "get signal " << signo <<std::endl; //<< " count is :" << std::endl;
    //std::cout << count << std::endl;
    //count = 0;
    //alarm(1);
    exit(2);
}

int main()
{
    // signal(SIGALRM, header);
    // alarm(1);
    // while (true)
    //{
    //  std::cout<<count<<std::endl;
    // count++;
    //}
    signal(2,header);
    pid_t id = fork();
    if (id == 0)
    {
        while(1)
        {
            std::cout<<"I am child process"<<std::endl;
            sleep(1);
        }
        exit(0);
    }
    sleep(5);
    kill(id, 2);
    return 0;
}
